package com.jie.deletefile.Gestures;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.jie.deletefile.R;

public class TestActivity extends AppCompatActivity {


    private GestureLockViewGroup mGestureLockViewGroup;
    private android.widget.TextView tvtest;
    private GestureLockViewGroup idgestureLockViewGroup;
    private android.widget.LinearLayout activitymain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        this.tvtest = (TextView) findViewById(R.id.tv_test);

        mGestureLockViewGroup = (GestureLockViewGroup) findViewById(R.id.id_gestureLockViewGroup);
        initAnswer();
        mGestureLockViewGroup
                .setOnGestureLockViewListener(new GestureLockViewGroup.OnGestureLockViewListener() {

                    @Override
                    public void onUnmatchedExceedBoundary() {
                        tvtest.setText("错误5次,请稍后再试");
                        tvtest.setText("请输入正确的密码");
                    }

                    @Override
                    public void onGestureEvent(boolean matched) {
                        if (matched) {
                            tvtest.setText("密码正确欢迎你");
                        } else {
                            tvtest.setText("密码错误,请重试");
                            mGestureLockViewGroup.reset();

                        }
                    }

                    @Override
                    public void onBlockSelected(int cId) {
                        Log.e("TAG", "onBlockSelected: " + cId);
                    }
                });
    }

    private void initAnswer() {
        SharedPreferences sp = getSharedPreferences("shoushi", MODE_PRIVATE);
        boolean isSetted = sp.getBoolean("isSetted", false);
        String answer = sp.getString("answer", null);
        Log.e("TAG", "initAnswer: "+answer );
        Integer[] array = DataUtils.string2integer(answer);
        if (isSetted != false && array.length != 0) {
            mGestureLockViewGroup.setAnswer(array);
        }
    }

}
